package com.sunday.common.mq.rocket.brave.study.apache.e1_Normal_Message;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.autoconfigure.ListenerContainerConfiguration;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

/**
 * https://github.com/apache/rocketmq-spring/wiki/Consume-Message
 */
@Slf4j
@Configuration
public class ConsumerConfig {

    /**
     * {@link DefaultRocketMQListenerContainer}
     * {@link ListenerContainerConfiguration#registerContainer(String, Object, RocketMQMessageListener)}
     */
    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "your_topic", consumerGroup = "your_consumer_group_name", consumeThreadNumber = 1)
    public static class MessageExtConsumer implements RocketMQListener<MessageExt> {
        @Override
        public void onMessage(MessageExt message) {
            log.info("{} - {}", new String(message.getBody()), message);
        }
    }


}
